package com.aiyige.arouter.Interceptor;

import android.content.Context;

import com.aiyige.arouter.config.ARouterConfig;
import com.aiyige.utils.AccountUtil;
import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.annotation.Interceptor;
import com.alibaba.android.arouter.facade.callback.InterceptorCallback;
import com.alibaba.android.arouter.facade.template.IInterceptor;
import com.alibaba.android.arouter.launcher.ARouter;


/**
 * Created by zhuyakun on 2017/12/15.
 */
@Interceptor(priority = 1)
public class LoginInterceptor implements IInterceptor {
    @Override
    public void process(Postcard postcard, InterceptorCallback callback) {
        if ((postcard.getExtra() & ARouterConfig.EXTRA_NEED_LOGIN) != 0 && !AccountUtil.isLogin()) {
            callback.onInterrupt(null);
            ARouter.getInstance()
                    .build(ARouterConfig.LoginPage)
//                    .withString("targetPage", postcard.getPath())
//                    .withBundle("targetData", postcard.getExtras())
                    .navigation();
        } else {
            callback.onContinue(postcard);
        }
    }

    @Override
    public void init(Context context) {

    }
}
